package com.ewhale.feitengguest.widget

import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ewhale.feitengguest.R
import com.ewhale.feitengguest.databinding.ItemScreenTipBinding
import com.ewhale.feitengguest.dto.ClassificationDto
import com.simga.library.adapter.BindRecycAdapter
import com.simga.library.utils.LogUtil
import com.simga.library.widget.BGButton
import java.util.logging.Logger

/**
 * 作者：SimGa
 * 日期：2019/12/25
 * 时间：11:53
 * 包名：com.ewhale.feitengguest.widget
 */
class ScreenBillDialog(context: Context) {
    private var mContext: Context? = null
    private val popupWindow: MPopuWindow
    private val inflater: LayoutInflater
    private val view: View

    init {
        mContext = context
        inflater = context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        view = inflater.inflate(R.layout.screenbill_layout, null)

        popupWindow = MPopuWindow(view,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        view.findViewById<View>(R.id.popu_ll).setOnClickListener {
            popupWindow.dismiss()
        }
        view.findViewById<BGButton>(R.id.btn_all).setOnClickListener {
            listener!!.onClick(3,"全部")
            popupWindow.dismiss()
        }
        view.findViewById<BGButton>(R.id.btn_shouru).setOnClickListener {
            listener!!.onClick(1,"收入")
            popupWindow.dismiss()
        }
        view.findViewById<BGButton>(R.id.btn_zhichu).setOnClickListener {
            listener!!.onClick(2,"支出")
            popupWindow.dismiss()
        }
    }

    private var listener: OnClickListener? = null

    fun setOnClickListener(listener: OnClickListener) {
        this.listener = listener
    }

    interface OnClickListener {
        fun onClick(type: Int,title:String)
    }

    fun showAsDropDown(parent: View) {
        popupWindow.showAsDropDown(
                parent)
        val cd = ColorDrawable(0x00000000)
        popupWindow.setBackgroundDrawable(cd)
        popupWindow.isFocusable = true
        popupWindow.isOutsideTouchable = true
        popupWindow.update()
    }
}
